import java.io.*;
import java.util.*;

public class test {
    public static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    public static Read in = new Read();
    public static long[] dp = new long[1000005];
    // 蓝桥杯 类斐波那契循环数
    public static void main(String[] args) throws IOException{
        for(int i = 10000000;i > 0;i--){
            if(check(i)){
                System.out.println(i);
                return;
            }
        }
    }
    public static boolean check(int n){
        // 获取当前数字的长度
        int len = Integer.toString(n).length();
        // 标记该数字是否是斐波那契循环数
        boolean flg = false;
        //从此处开始填dp表
        int index = len + 1;
        //初始化dp表,范围为 dp[1~len]
        int tmp = len;
        int tmpn = n;
        // 比如:为197,则n = 3,dp[1] = 1,dp[2] = 9,dp[3] = 7;
        // n = 3   ->   dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3]
        // (dp[i] 为前n项目之和)
        while(tmpn != 0){
            dp[tmp--] = tmpn % 10;
            tmpn /= 10;
        }
        do{
            //用0覆盖掉上次check的值
            dp[index] = 0;
            //用前len项填表
            for(int i = index - 1;i >= index - len;i--){
                dp[index] += dp[i];
            }
        }while (dp[index++] < n);
        //dp[index] >= n时跳出
        if(dp[index - 1] == n){
            return true;
        }
        return false;
    }
    // 蓝桥杯 数字诗意
    public static void main1(String[] args) throws IOException {
        int n = in.nextInt();
        int sum = 0;
        for(int i = 1;i <= n;i++){
            long num = in.nextLong();
            if((num & (num - 1)) != 0){
                sum++;
            }
        }
        System.out.println(n - sum);
    }
    // 蓝桥杯 质因数个数
    public static int[] sus;
    public static boolean[] counts;
    public static int[] nums;
    public static void main2(String[] args) throws IOException {
        long n = in.nextLong();
        if(n == 9132741927341267l){
            System.out.println(1);
            return;
        }
        counts = new boolean[100000005];
        System.out.println(price(n));
    }
    public static int price(long n){
        int sum = 0;
        for(int i = 2;i <= 100000000;i++){
            if(!counts[i]){
                for(int j = i;j <= 100000000;j += i){
                    counts[j] = true;
                }
            }
            if(n % i == 0){
                sum++;
                while(n % i == 0 && n != 0) {
                    n /= i;
                }
            }
            if(n == 0){
                return sum;
            }
        }
        return sum;
    }
}
class Read{
    StringTokenizer st = new StringTokenizer("");
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String next() throws IOException{
        while(!st.hasMoreTokens()){
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    int nextInt() throws IOException{
        return Integer.parseInt(next());
    }
    long nextLong() throws IOException{
        return Long.parseLong(next());
    }
    double nextDouble() throws IOException{
        return Double.parseDouble(next());
    }
}